package com.example.chapter4.service.iml;

import com.example.chapter4.entity.Blog;
import com.example.chapter4.mapper.BlogMapper;
import com.example.chapter4.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BlogServiceIml implements BlogService {
    @Autowired
    BlogMapper blogMapper;
    @Override
    public List<Blog> findAll() {
        //调用Mapper，查询所有博客的数据
        return blogMapper.findAll();
    }
    //分页查询
    @Override
    public List<Blog> findBlogsByPage(int page, int pageSize) {
        //计算offset
        int offset = (page - 1) * pageSize;
        return blogMapper.findBlogsByPage(offset, pageSize);
    }
    //获取博客数量
    @Override
    public int countBlogs() {
        return blogMapper.countBlogs();
    }

    @Override
    public boolean updateBlog(Blog blog) {
        return blogMapper.updateBlog(blog) > 0;
    }

    @Override
    public boolean deleteBlog(int id) {
        return blogMapper.deleteBlog(id) > 0;
    }
}
